package com.yylending.las.personal.feedback;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;

import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by HenryZhang on 2016/11/18.
 * Copyright © 2016 www.yyfax.com. All Rights Reserved.
 */
public class FeedbackModel extends Model {
	private static final String TAG = "FeedbackModel";

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		return service.feedback(Global.LOGIN_TOKEN, (AESEntity) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		FeedbackResult result = cast(obj);
		EventAgent.post(result);
	}

	private interface Service {
		/**
		 * 问题反馈
		 */
		@POST("server/suggest/addSuggestion")
		Observable<FeedbackResult> feedback(@Header("token") String token, @Body AESEntity feedback);
	}

	static class FeedbackResult extends BaseResultEntity<EmptyEntity> {
	}

	public static class FeedBack {
		public String content;

		public FeedBack(String content) {
			this.content = content;
		}
	}
}